package 小练习;

public class ArrayQueue { //能够实现输入多大的maxSize数值就能够存多少，早晚一天我要实现这个代码
    int front;
    int rear;
    int maxSize;
    int[] arr;
    int flag;

    ArrayQueue(int max){
        maxSize  = max;
        front = 0;
        rear = 0;
        arr = new int[maxSize];
    }

    //判断是否为满
    boolean isFull(){
        return rear == front;
    }

    //判断是否为空
    boolean isEmpty(){
        return rear == front;
    }

    void addQueue(int data){
        if(isFull()){
            System.out.println("队列满，添加数据");
            return;
        }
        rear++;
        arr[rear] = data;
        flag++;
    }

    int getQueue(){
        if(isEmpty()){
            throw new RuntimeException("无法取出数据，数组为空");
        }
        int value = arr[front];
        front++;
        flag--;
        return value;
    }

    int size(){
        return (rear + 1 + maxSize - front) % maxSize;
    }
}
